﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Base;
using nspLable.Manage;
using Product;
using System.Text;

public partial class admin_Lable_Model_IndexIndustry : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckRights("Template", "A1");
        if (!IsPostBack)
        {
            if (Request.QueryString["ID"] != null)
            {

                SystemLableTypeBind();
                Bind();
            }
            else
            {
                SystemLableTypeBind();

            }

        }
    }
    private void Bind()
    {
        int id = int.Parse(Request.QueryString["ID"].ToString());
        ISystemLable RSystem = new RSystemLable();
        TSystemLable TSystem = RSystem.GateItem(id);

        txtEngLishName.Text = TSystem.Name.Substring(3);
        txtChineseName.Text = TSystem.Remarks;
        dropLableType.SelectedValue = TSystem.TypeID.ToString();
        if (TSystem.Info != null)
        {
            string[] str = TSystem.Info.Split(new char[] { '|' });
            dropWhicType.SelectedValue = str[0];
            topType.SelectedValue = str[1];
            topCss.Text = str[2];
            topTitleCss.Text = str[3];
            UlCss.Text = str[4];
        }
    }

    private void SystemLableTypeBind()
    {
        ISystemLableType RSystem = new RSystemLableType();
        DataTable dt = RSystem.GetDataTable(0);
        dropLableType.DataSource = dt.DefaultView;
        dropLableType.DataValueField = "ID";
        dropLableType.DataTextField = "Name";
        dropLableType.DataBind();

        IIndustryType IIndust = new RIndustryType();
        DataTable dt1 = IIndust.GetDataTable(0);
        topType.DataSource = dt1.DefaultView;
        topType.DataValueField = "ID";
        topType.DataTextField = "Type";
        topType.DataBind();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {

        if (Request.QueryString["ID"] != null)
        {
            try
            {
                string myValue = "";
                int id = int.Parse(Request.QueryString["ID"].ToString());
                TSystemLable TSystem = new TSystemLable();
                TSystem.ID = id;
                TSystem.Name = "SY_" + txtEngLishName.Text;
                TSystem.Remarks = txtChineseName.Text;
                TSystem.TypeID = int.Parse(dropLableType.SelectedValue);
                TSystem.Title = "SY_IndexIndustry";
                StringBuilder stringStr = new StringBuilder();
                stringStr.Append(dropWhicType.SelectedValue + "|");    //行业类别
                stringStr.Append(topType.SelectedValue + "|");
                stringStr.Append(topCss.Text + "|");
                stringStr.Append(topTitleCss.Text + "|");
                stringStr.Append(UlCss.Text);

                TSystem.Info = stringStr.ToString();
                ISystemLable RSystem = new RSystemLable();
                RSystem.Update(TSystem);
                Messagess.ShowMessage("标签修改成功！");
                Response.Write("<script>window.parent.window.location.href='../SystemLable/SystemLableManage.aspx'</script>");
            }
            catch (Exception ex)
            {
                ShowMessage("标签修改失败!", "Lable/SystemLable/SystemLableManage.aspx");
            }
        }
        else
        {
            try
            {
                string myValue = "";
                TSystemLable TSystem = new TSystemLable();
                TSystem.Name = "SY_" + txtEngLishName.Text;
                TSystem.Remarks = txtChineseName.Text;
                TSystem.TypeID = int.Parse(dropLableType.SelectedValue);
                TSystem.Title = "SY_IndexIndustry";

                StringBuilder stringStr = new StringBuilder();
                stringStr.Append(dropWhicType.SelectedValue + "|");    //行业类别
                stringStr.Append(topType.SelectedValue + "|");
                stringStr.Append(topCss.Text + "|");
                stringStr.Append(topTitleCss.Text + "|");
                stringStr.Append(UlCss.Text);
                TSystem.Info = stringStr.ToString();

                ISystemLable RSystem = new RSystemLable();
                RSystem.Insert(TSystem);
                Messagess.ShowMessage("标签修改成功！");
                Response.Write("<script>window.parent.window.location.href='../SystemLable/SystemLableManage.aspx'</script>");
            }
            catch (Exception ex)
            {
                ShowMessage("标签添加失败!", "Lable/SystemLable/SystemLableManage.aspx");
            }
        }
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Write("<script>window.parent.window.location.href='../SystemLable/SystemLableManage.aspx'</script>");
    }
}
